#include "stdafx.h"
#include "drawingBrickInCMD.h"


Brick RotaBrcik(Brick b)
{
	Brick newb = b;
	int i;
	for(i=0;i<MAX_BRICKS;i++)
	{
		newb.locations[i].y = b.locations[i].x;
		newb.locations[i].x = b.size.x-1 - b.locations[i].y;
	}
	return newb;
}

void DrawBrick(HANDLE h, Point p,Brick b)
{
	int i=0;
	int loc_x,loc_y;
	GotoXY(h,p.x,p.y);
	for(i=0;i<MAX_BRICKS;i++)
	{
		loc_x = p.x+b.locations[i].x*2;
		loc_y = p.y+(b.locations[i].y);
		GotoXY(h,loc_x,loc_y);
		DrawString(h,loc_x,loc_y,b.type,NULL);
	}
}
void DrawBrickInMain(HANDLE h, Point p,Brick b)
{
	int i=0;
	int loc_x,loc_y;
	GotoXY(h,p.x,p.y);
	for(i=0;i<MAX_BRICKS;i++)
	{
		loc_x = (p.x+b.locations[i].x)*2+2;
		loc_y = p.y+(b.locations[i].y)+1;
		GotoXY(h,loc_x,loc_y);
		if(loc_y>0)
			DrawString(h,loc_x,loc_y,b.type,NULL);
	}
}

void DrawLineDisappear(HANDLE h,int num,int loc[])
{
	if(num>0 && num<=MAX_BRICKS)
	{
		int i;
		for(i=0;i<num;i++)
		{
			DrawBlank(h,2,loc[i]+1,SIZE_MAIN_WIDTH*2,1);
		}
		Sleep(300);
	}
}
void DrawBrickChange(HANDLE h,Point* p,Brick* old_b,int x,int y,short r)
{
	char t[3];
	strcpy(t,(*old_b).type);
	strcpy((*old_b).type,"  ");
	DrawBrickInMain(h,*p,*old_b);
	strcpy((*old_b).type,t);
	if(x==0)
		;
	else if(x==1)
		(*p).x++;
	else if(x==-1)
		(*p).x--;
	if(y==0)
		;
	else if(y)
		(*p).y += y;
	if(r==1)
	{
		Brick b =  RotaBrcik(*old_b);
		DrawBrickInMain(h,*p,b);
		(*old_b) = b;
	}
	else if(r==0)
	{
		DrawBrickInMain(h,*p,*old_b);
	}
}